package com.controller;

import com.pojo.GroupIntroduction;
import com.service.GroupIntroductionService;
import com.util.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Administrator on 2020/3/20.
 */
@Api(tags = "团购产品介绍API")
@Controller
public class GroupIntroductionController {
    @Autowired
    private GroupIntroductionService groupIntroductionService;
    @ApiOperation(value ="添加团购产品介绍",notes ="" )
    @PostMapping("/groupIntroduction")
    @ResponseBody
    public ServerResponse add(GroupIntroduction groupIntroduction){
        // ServerResponse serverResponse =
        //System.out.println("serverResponse:"+serverResponse);
        return groupIntroductionService.save(groupIntroduction);
    }
    @ApiOperation(value = "删除团购产品介绍",notes ="修改状态")
    @DeleteMapping("/groupIntroduction/{id}")
    @ResponseBody
    public ServerResponse del(@PathVariable("id")String id){
        ServerResponse serverResponse = groupIntroductionService.modifyStatus(Integer.valueOf(id));
        System.out.println("serverResponse:"+serverResponse);
        return serverResponse;
    }

    @ApiOperation(value ="修改团购产品介绍",notes ="应该用不到" )
    @PutMapping("/groupIntroduction")
    @ResponseBody
    public ServerResponse upd(GroupIntroduction groupIntroduction){
        System.out.println(groupIntroduction);
        ServerResponse serverResponse = groupIntroductionService.modify(groupIntroduction);
        return serverResponse;
    }
    @ApiOperation(value ="根据团购产品介绍id查询")
    @GetMapping("/groupIntroduction/{id}")
    @ResponseBody
    public ServerResponse findById(@PathVariable("id") String id){
        System.out.println(id);
        ServerResponse serverResponse = groupIntroductionService.getById(Integer.valueOf(id));
        return serverResponse;
    }

    @ApiOperation(value ="查询团购产品介绍信息")
    @GetMapping("/groupIntroduction")
    @ResponseBody
    public ServerResponse findAll(){
        ServerResponse serverResponse = groupIntroductionService.getAll();
        return serverResponse;
    }

    @ApiOperation(value = "获得团购产品介绍的主页面",notes = "团购产品介绍端")
    @GetMapping("/groupIntroduction/backhome")
    public String goUserBackHome(Model model){
        ServerResponse serverResponse = groupIntroductionService.getAll();
        model.addAttribute("info",serverResponse.getData());
        return "back/group/groupintroductionbackhome";
    }
}
